<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Auth;

class Shop extends Authenticatable
{

    use Notifiable, HasApiTokens;
    
    /**
     * 获得拥有此店铺的用户。
     */
    public function user()
    {
        return $this->belongsTo('App\Models\User', 'user_id');
    }

    /**
     * 获得店铺的商品
     */
    public function products()
    {
        return $this->hasMany('App\Models\Product');
    }

    /**
     * 提现
     */
    public function withdraw()
    {
        return $this->hasMany('App\Models\Withdraw');
    }

    public function scopeOwner($query)
    {
        return $query->where('shop_id', Auth::guard('shop')->id);
    }

    /**
     * 营业执照图片URL
     */
    public function getLicenseUrlAttribute(){
        if (isset($this->attributes['license'])) {
            return config('app.url').'/storage/uploads/images/' . $this->attributes['license'];
        }
    }
}
